package com.jflm.controller.api;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.jflm.base.BaseAction;
import com.jflm.domain.DataInterfaceManagement;
import com.jflm.service.IDataInterfaceManagementService;

@RestController
@RequestMapping("/api/dataInterfaceManagement")
public class DataInterfaceManagementAction extends BaseAction{
	
	private static final Logger LOG = LoggerFactory.getLogger(DataInterfaceManagementAction.class);
	
	@Autowired
	private IDataInterfaceManagementService dataInterfaceManagementService;
	
	/**
	 * ******************************************* 
	 * method name : findList
	 * description : 查询全部规则
	 * @author     : xusai
	 * @return 	   : List<DataInterfaceManagement>
	 * @param 	   : @throws Exception
	 * @see 	   : 
	 * *******************************************
	 * */
	@PostMapping(value = "/findList")
	public List<DataInterfaceManagement> findList(@RequestBody DataInterfaceManagement dataInterfaceManagement) throws Exception {
		LOG.info("#findList() 请求参数：{}", gson.toJson(dataInterfaceManagement));
		List<DataInterfaceManagement> reList = dataInterfaceManagementService.findList(dataInterfaceManagement);
		LOG.info("#findList() 响应参数：{}", gson.toJson(dataInterfaceManagement));
		return reList;
	}
	
	/**
	 * ******************************************* 
	 * method name : addPage
	 * description : 新增通道
	 * @author     : xusai
	 * @return 	   : List<DataInterfaceManagement>
	 * @param 	   : @throws Exception
	 * @see 	   : 
	 * *******************************************
	 * */
	@PostMapping(value="/addPage")
	public int add(@RequestBody DataInterfaceManagement dataInterfaceManagement) throws Exception{
		String uuid = UUID.randomUUID().toString().replaceAll("-", "");
		Date date = new Date();       
		Timestamp nowdate = new Timestamp(date.getTime());
		dataInterfaceManagement.setId(uuid);
		dataInterfaceManagement.setDel(0);
		dataInterfaceManagement.setCreateTime(nowdate);
		dataInterfaceManagement.setType("第三方");
		dataInterfaceManagement.setNumber(0);
		dataInterfaceManagement.setState("0");
		int flag = dataInterfaceManagementService.add(dataInterfaceManagement);
		return flag;
	}
	
	/**
	 * ******************************************* 
	 * method name : findOne
	 * description : 查询单条数据
	 * @author     : xusai
	 * @return 	   : List<DataInterfaceManagement>
	 * @param 	   : @throws Exception
	 * @see 	   : 
	 * *******************************************
	 * */
	@RequestMapping(value = "/findOne", method = RequestMethod.POST)
	public DataInterfaceManagement findOne(@RequestBody DataInterfaceManagement dataInterfaceManagement) throws Exception {
		dataInterfaceManagement= dataInterfaceManagementService.findOne(dataInterfaceManagement.getId());
		LOG.info("#findOne() 响应参数：{}", gson.toJson(dataInterfaceManagement));
		return dataInterfaceManagement;
	}
	
	/**
	 * ******************************************* 
	 * method name : updatePage
	 * description : 修改通道
	 * @author     : xusai
	 * @return 	   : int
	 * @param 	   : @throws Exception
	 * @see 	   : 
	 * *******************************************
	 * */
	@PostMapping(value = "/updatePage")
	public int updatePage(@RequestBody DataInterfaceManagement dataInterfaceManagement) throws Exception {
		int rul = dataInterfaceManagementService.update(dataInterfaceManagement);
		return rul;
	}
	
	/**
	 * ******************************************* 
	 * method name : deletePage
	 * description : 禁用通道
	 * @author     : xusai
	 * @return 	   : int
	 * @param 	   : @throws Exception
	 * @see 	   : 
	 * *******************************************
	 * */
	@RequestMapping(value = "/deletePage", method = RequestMethod.POST)
	public int deletePage(@RequestBody DataInterfaceManagement dataInterfaceManagement) throws Exception {
		if(dataInterfaceManagement.getState().equals("0")){
			dataInterfaceManagement.setState("1");
		}else{
			dataInterfaceManagement.setState("0");
		}
		int rul = dataInterfaceManagementService.delete(dataInterfaceManagement);
		LOG.info("#deletePage() 响应参数：{}", gson.toJson(dataInterfaceManagement));
		return rul;
	}
}
